package controllers;

import helpers.StringHelper;
import helpers.UrlHelper;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public final class UrlFilterServlet implements Filter {
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		String sub = UrlHelper.getSubDomain(((HttpServletRequest) request).getServerName());
		String language = null;
		if (sub.equals("en")) {
			language = "en";
		} else {
			language = "ja";
		}
		request.setAttribute("language", language);
		chain.doFilter(request, response);
	}

	public void destroy() {

	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
	}
}